#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv) {
  const int N_repeat = 100;
  const int MessageSize=10000000;
  int* message = (int*) malloc(MessageSize*sizeof(int));
  int i;
  double total_time=0;
  for(i=0;i<MessageSize;++i)
    message[i]=0;

  MPI_Init(NULL, NULL);
  int rank;
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  int world_size;
  MPI_Comm_size(MPI_COMM_WORLD, &world_size);
  
  while (message[0] < N_repeat) 
  {
    message[0]++;
    double t1 = MPI_Wtime();
    MPI_Send(message, MessageSize, MPI_INT, rank, 0, MPI_COMM_WORLD);
    MPI_Recv(message, MessageSize, MPI_INT, rank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
    double t2=(MPI_Wtime()-t1);
    total_time+=t2;
  }
  MPI_Finalize();
  printf("\n%f\n ",total_time/N_repeat);
  free(message);
  return 0;
